package com.mg.smarttask.client;

import com.google.gwt.user.client.ui.*;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class NotesWindow extends Composite {
	Button seeAll = new Button("Tout afficher");
	Button newNote = new Button();
	Button sharedNotes = new Button("Notes partag\u00E9es");
	public ShowNotes showNotes;
	EditNote editNote;
	AddNote addNote;
	public ShowSharedNotes showSharedNotes;
	public NotesWindow() {	
		//loading Widgets
		showNotes = new ShowNotes(this);
		showSharedNotes = new ShowSharedNotes(this);
		editNote  = new EditNote(this);
		addNote = new AddNote(this);
		
		VerticalPanel verticalPanel = new VerticalPanel();
		verticalPanel.setStyleName("loginPanel");
		initWidget(verticalPanel);
		Label titleLabel = new Label("Notes");
		titleLabel.setStyleName("h2");
		//verticalPanel.add(titleLabel);
		//titleLabel.setSize("700px","30px");
		
		HorizontalPanel menuPanel = new HorizontalPanel();
		HorizontalPanel menuPanelSub = new HorizontalPanel();
		menuPanel.setStyleName("subMenuPanel");
		seeAll.setStyleName("subButtonLeft");
		newNote.setStyleName("subButtonAdd");
		sharedNotes.setStyleName("subButtonRight");
		menuPanelSub.add(titleLabel);
		menuPanelSub.add(seeAll);
		menuPanelSub.add(sharedNotes);
		menuPanelSub.add(newNote);	
		menuPanel.add(menuPanelSub);	

		//Here the menu is added in the panel
		verticalPanel.add(menuPanel);
		//THis will content the subContent of the page
		final VerticalPanel subContentPanel  = new VerticalPanel();	
		subContentPanel.setStyleName("subContent");
		subContentPanel.add(showNotes);
		seeAll.addStyleName("subActiveButton");
		
		//The contentPanel is added to the subContentPanel
		verticalPanel.add(subContentPanel);
		
		
		//Buttons events from here
		seeAll.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				seeAll.addStyleName("subActiveButton");
				sharedNotes.removeStyleName("subActiveButton");
				newNote.removeStyleName("subActiveButton");
				subContentPanel.remove(showSharedNotes);
				subContentPanel.remove(addNote);
				subContentPanel.add(showNotes);
				showNotes.loadNotesFromServer();
				showNotes.updateNotePanel();
			}
		});
		
		sharedNotes.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				seeAll.removeStyleName("subActiveButton");
				sharedNotes.addStyleName("subActiveButton");
				newNote.removeStyleName("subActiveButton");
				subContentPanel.remove(showNotes);
				subContentPanel.remove(addNote);
				subContentPanel.add(showSharedNotes);
			}
		});
		newNote.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				if(showSharedNotes.isAttached()){
					subContentPanel.remove(showSharedNotes);
					subContentPanel.add(addNote);				
					subContentPanel.add(showSharedNotes);
				}
				else if(showNotes.isAttached()){
					subContentPanel.remove(showNotes);
					subContentPanel.add(addNote);				
					subContentPanel.add(showNotes);
				}
				else {
					subContentPanel.add(addNote);				
				}
			}
		});
	}

}
